package debugServer;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;

import YAPenvironment.YAPconstant;
import YAPserver.YAPserver;

public class FormDebugConsole extends JFrame implements ActionListener{
	
	JTabbedPane lobbies = new JTabbedPane();
	
	JButton refresh = new JButton("Refresh"); //used to refresh which lobbies are up
	
	FormDebugConsole(){
		createGUI();
	}

	private void createGUI() {
		refresh.addActionListener(this);
		refresh.setSize(30,10);
		
		this.getContentPane().add(refresh, BorderLayout.SOUTH);
		this.getContentPane().add(lobbies, BorderLayout.NORTH);
		//TODO: format position of button	
		
		setTitle("Debug Console");
		setIconImage(YAPconstant.ICONIMAGE);
		setLocationRelativeTo(null);
		setResizable(true);
		setVisible(true);
		this.pack();
	}
	
	private void createTabs(){
		//figure out how to refresh	
		lobbies.removeAll();
		for(String lobby: DebugServer.lobbyList.keySet()){
			lobbies.addTab(lobby, new DebugPanel(DebugServer.lobbyList.get(lobby)));
			this.pack();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		createTabs();
	}
}
